﻿// Decompiled with JetBrains decompiler
// Type: DnProcessSimulateCommands.CApCableStatusMessageFactory
// Assembly: DnProcessSimulateCommands, Version=2402.0.0.890, Culture=neutral, PublicKeyToken=null
// MVID: A885D881-AEDF-447E-852A-6F13102E089C
// Assembly location: C:\Program Files\Tecnomatix_2402\eMPower\DotNetCommands\DnProcessSimulateCommands.dll

using DnProcessSimulateCommands.Flexibles;
using System;
using System.Collections.Generic;
using System.Linq;
using Tecnomatix.Engineering;


namespace DnProcessSimulateCommands;

internal class CApCableStatusMessageFactory : ICApCableStatusMessageFactory
{
  private List<CApCableStatusMessageFactory.ErrorMessageDelegate> m_orderedCableStatusMessage;
  private readonly CApCableStatusAnalysis m_cableStatusAnalysis;

  internal CApCableStatusMessageFactory(CApCableStatusAnalysis cableStatusAnalysis)
  {
    this.m_cableStatusAnalysis = cableStatusAnalysis ?? throw new ArgumentNullException(nameof (cableStatusAnalysis));
    this.InitOrderedCableStatusMessageList();
  }

  public ICApCableStatusMessage ComputePriorityErrorMessage()
  {
    CApCableStatusMessage priorityErrorMessage = new CApCableStatusMessage();
    foreach (CApCableStatusMessageFactory.ErrorMessageDelegate errorMessageDelegate in this.m_orderedCableStatusMessage)
    {
      priorityErrorMessage = this.ComputeErrorMessage(errorMessageDelegate);
      if (priorityErrorMessage.MessageType != CApCableStatusMessageType.None)
        break;
    }
    return (ICApCableStatusMessage) priorityErrorMessage;
  }

  public ICApCableStatusMessage ComputeCableLengthErrorMessage()
  {
    CApCableStatusMessage cableStatusMessage = new CApCableStatusMessage();
    CApCableStatusMessage errorMessage = this.ComputeErrorMessage(new CApCableStatusMessageFactory.ErrorMessageDelegate(this.ComputeDistanceBetweenStartAndEndFrameStatus));
    if (errorMessage.MessageType == CApCableStatusMessageType.None)
      errorMessage = this.ComputeErrorMessage(new CApCableStatusMessageFactory.ErrorMessageDelegate(this.ComputeAttachmentsLengthStatus));
    if (errorMessage.MessageType == CApCableStatusMessageType.None)
      errorMessage = this.ComputeErrorMessage(new CApCableStatusMessageFactory.ErrorMessageDelegate(this.ComputeDistanceBetweenAttachmentsFrameStatus));
    return (ICApCableStatusMessage) errorMessage;
  }

  private void InitOrderedCableStatusMessageList()
  {
    this.m_orderedCableStatusMessage = new List<CApCableStatusMessageFactory.ErrorMessageDelegate>()
    {
      new CApCableStatusMessageFactory.ErrorMessageDelegate(this.AreStartAndEndFramesEmpty),
      new CApCableStatusMessageFactory.ErrorMessageDelegate(this.IsStartFrameEmpty),
      new CApCableStatusMessageFactory.ErrorMessageDelegate(this.IsEndFrameEmpty),
      new CApCableStatusMessageFactory.ErrorMessageDelegate(this.IsOptimizationPointCloudLayerEmpty),
      new CApCableStatusMessageFactory.ErrorMessageDelegate(this.ComputeRadiusStatus),
      new CApCableStatusMessageFactory.ErrorMessageDelegate(this.ComputeStartEndNotAttachedToEquipmentStatus),
      new CApCableStatusMessageFactory.ErrorMessageDelegate(this.ComputeStartAndEndFrameAttachedToSameRobotStatus),
      new CApCableStatusMessageFactory.ErrorMessageDelegate(this.ComputeDistanceBetweenStartAndEndFrameStatus),
      new CApCableStatusMessageFactory.ErrorMessageDelegate(this.ComputeCableLengthStatus),
      new CApCableStatusMessageFactory.ErrorMessageDelegate(this.ComputeZAxisFreeRotatingAttachmentsStatus),
      new CApCableStatusMessageFactory.ErrorMessageDelegate(this.ComputeAttachmentsLengthStatus),
      new CApCableStatusMessageFactory.ErrorMessageDelegate(this.ComputeDistanceBetweenAttachmentsFrameStatus),
      new CApCableStatusMessageFactory.ErrorMessageDelegate(this.ComputePercentageLengthAttachmentsStatus),
      new CApCableStatusMessageFactory.ErrorMessageDelegate(this.ComputeFulcrumLengthStatus),
      new CApCableStatusMessageFactory.ErrorMessageDelegate(this.ComputeAttachmentAndPassNearStatus),
      new CApCableStatusMessageFactory.ErrorMessageDelegate(this.ComputePassNearStatus),
      new CApCableStatusMessageFactory.ErrorMessageDelegate(this.ComputeRobotAttachmentFrameStatus),
      new CApCableStatusMessageFactory.ErrorMessageDelegate(this.ComputeAttachmentsFrameAttachementStatus)
    };
  }

  private CApCableStatusMessage ComputeErrorMessage(
    CApCableStatusMessageFactory.ErrorMessageDelegate errorMessageDelegate)
  {
    CApCableStatusMessage errorMessage = new CApCableStatusMessage();
    if (errorMessageDelegate != null)
      errorMessage = errorMessageDelegate();
    return errorMessage;
  }

  private CApCableStatusMessage ComputeStartEndNotAttachedToEquipmentStatus()
  {
    CApCableStatusMessage toEquipmentStatus = new CApCableStatusMessage();
    if (this.m_cableStatusAnalysis.IsCableInEquipment)
    {
      string name = this.m_cableStatusAnalysis.ParentEquipment.Name;
      bool equipment1 = this.m_cableStatusAnalysis.IsStartFrameProperlyAttachedToEquipment();
      bool equipment2 = this.m_cableStatusAnalysis.IsEndFrameProperlyAttachedToEquipment();
      if (!equipment1 || !equipment2)
      {
        toEquipmentStatus.MessageType = CApCableStatusMessageType.Error;
        toEquipmentStatus.MessageText = equipment1 || equipment2 ? (equipment1 ? string.Format(CApFLEXStringTable.EndFrameNotAttachedToEquipmentMessage, (object) name) : string.Format(CApFLEXStringTable.StartFrameNotAttachedToEquipmentMessage, (object) name)) : string.Format(CApFLEXStringTable.StartEndFramesNotAttachedToEquipmentMessage, (object) name);
      }
    }
    return toEquipmentStatus;
  }

  private CApCableStatusMessage ComputeStartAndEndFrameAttachedToSameRobotStatus()
  {
    CApCableStatusMessage toSameRobotStatus = new CApCableStatusMessage();
    if (!this.m_cableStatusAnalysis.AreStartEndFrameAttachedToSameRobot())
    {
      toSameRobotStatus.MessageText = CApFLEXStringTable.FrameAreNotAttachedInSameRobotMessage;
      toSameRobotStatus.MessageType = CApCableStatusMessageType.Error;
    }
    return toSameRobotStatus;
  }

  private CApCableStatusMessage ComputeRadiusStatus()
  {
    CApCableStatusMessage radiusStatus = new CApCableStatusMessage();
    if (!this.m_cableStatusAnalysis.IsRadiusOptimizationEnabled && this.m_cableStatusAnalysis.Radius == 0.0)
    {
      radiusStatus.MessageText = CApFLEXStringTable.CableRadiusErrorMessage;
      radiusStatus.MessageType = CApCableStatusMessageType.Error;
    }
    return radiusStatus;
  }

  private CApCableStatusMessage ComputeDistanceBetweenStartAndEndFrameStatus()
  {
    CApCableStatusMessage andEndFrameStatus = new CApCableStatusMessage();
    double distance;
    if (CApCableUtility.ComputeDistanceBetweenFrames(this.m_cableStatusAnalysis.StartFrame, this.m_cableStatusAnalysis.EndFrame, out distance) && this.m_cableStatusAnalysis.Length < distance)
    {
      double valueWithCurrentUnit = CApCableUtility.ComputeLinearRoundValueWithCurrentUnit(distance);
      andEndFrameStatus.MessageText = string.Format(CApFLEXStringTable.CableCannotReachStartAndEndFrames, (object) valueWithCurrentUnit.ToString(CApCableUtility.NumericLinearFormat), (object) TxApplication.Options.Units.LinearUnitName, (object) ((ITxObject) this.m_cableStatusAnalysis.StartFrame).Name, (object) ((ITxObject) this.m_cableStatusAnalysis.EndFrame).Name);
      andEndFrameStatus.MessageType = CApCableStatusMessageType.Error;
    }
    return andEndFrameStatus;
  }

  private CApCableStatusMessage ComputeCableLengthStatus()
  {
    CApCableStatusMessage cableLengthStatus = new CApCableStatusMessage();
    if (!this.m_cableStatusAnalysis.IsLengthOptimizationEnabled)
    {
      double betweenAttachments = this.m_cableStatusAnalysis.MinimalLengthBetweenAttachments;
      if (this.m_cableStatusAnalysis.Length < betweenAttachments)
      {
        cableLengthStatus.MessageText = string.Format(CApFLEXStringTable.CableLengthIsTooShortMessage, (object) betweenAttachments.ToString(CApCableUtility.NumericLinearFormat), (object) TxApplication.Options.Units.LinearUnitName);
        cableLengthStatus.MessageType = CApCableStatusMessageType.Error;
      }
    }
    return cableLengthStatus;
  }

  private CApCableStatusMessage ComputeZAxisFreeRotatingAttachmentsStatus()
  {
    CApCableStatusMessage attachmentsStatus = new CApCableStatusMessage();
    if (this.IsParametersCreationMode() && this.m_cableStatusAnalysis.DoesContainOnlyZAxisFreeRotatingAttachments())
    {
      attachmentsStatus.MessageText = CApFLEXStringTable.CableContainsOnlyZAxisFreeRotatingAttachmentsErrorMessage;
      attachmentsStatus.MessageType = CApCableStatusMessageType.Error;
    }
    return attachmentsStatus;
  }

  private CApCableStatusMessage ComputeAttachmentsLengthStatus()
  {
    bool flag = true;
    CApCableStatusMessage attachmentsLengthStatus = new CApCableStatusMessage();
    if (this.IsParametersCreationMode())
    {
      if (!this.m_cableStatusAnalysis.AreAttachmentsLengthSmallerThanCableLength())
      {
        attachmentsLengthStatus.MessageText = CApFLEXStringTable.AttachmentLengthAreInvalid;
        attachmentsLengthStatus.MessageType = CApCableStatusMessageType.Error;
        flag = false;
      }
      CApFLEXAttachmentErrorMessage errorMessage;
      if (flag && !this.m_cableStatusAnalysis.IsAttachmentLengthConsistentWithSecondaryAttachmentLength(out errorMessage))
      {
        attachmentsLengthStatus.MessageText = errorMessage.GetErrorMessage();
        attachmentsLengthStatus.MessageType = CApCableStatusMessageType.Error;
        flag = false;
      }
      if (flag && !this.m_cableStatusAnalysis.IsAttachmentLengthConsistentWithRetractSystem(out errorMessage))
      {
        attachmentsLengthStatus.MessageText = errorMessage.GetErrorMessage();
        attachmentsLengthStatus.MessageType = CApCableStatusMessageType.Error;
      }
    }
    return attachmentsLengthStatus;
  }

  private CApCableStatusMessage ComputeDistanceBetweenAttachmentsFrameStatus()
  {
    CApCableStatusMessage attachmentsFrameStatus = new CApCableStatusMessage();
    if (this.IsParametersCreationMode() && this.m_cableStatusAnalysis.AttachmentDataList.Any<CApFLEXAttachment>())
    {
      CApFLEXAttachmentErrorMessage attachmentStatus = this.ComputeDistanceBetweenAttachmentsFrameAttachmentStatus();
      attachmentsFrameStatus.MessageText = attachmentStatus.GetErrorMessage();
      attachmentsFrameStatus.MessageType = attachmentStatus.AttachmentErrorType != CApFLEXAttachmentErrorMessage.EAttachmentErrorType.None ? CApCableStatusMessageType.Error : CApCableStatusMessageType.None;
    }
    return attachmentsFrameStatus;
  }

  private CApCableStatusMessage ComputePercentageLengthAttachmentsStatus()
  {
    CApCableStatusMessage attachmentsStatus = new CApCableStatusMessage();
    CApFLEXAttachmentErrorMessage errorMessage;
    if (this.IsParametersCreationMode() && this.m_cableStatusAnalysis.AttachmentDataList.Any<CApFLEXAttachment>() && !this.m_cableStatusAnalysis.ArePercentageLengthBetweenAttachmentsValid(out errorMessage))
    {
      attachmentsStatus.MessageText = errorMessage.GetErrorMessage();
      attachmentsStatus.MessageType = CApCableStatusMessageType.Error;
    }
    return attachmentsStatus;
  }

  private CApCableStatusMessage ComputeFulcrumLengthStatus()
  {
    CApCableStatusMessage fulcrumLengthStatus = new CApCableStatusMessage();
    double fulcrumMinDistance;
    if (!this.m_cableStatusAnalysis.IsLengthOptimizationEnabled && !this.m_cableStatusAnalysis.IsFulcrumLengthValid(out fulcrumMinDistance))
    {
      fulcrumMinDistance = CApCableStatusAnalysis.ComputeValueWithCurrentLinearUnit(fulcrumMinDistance);
      fulcrumLengthStatus.MessageText = string.Format(CApFLEXStringTable.FulCrumLengthIsInvalid, (object) fulcrumMinDistance.ToString(CApCableUtility.NumericLinearFormat), (object) TxApplication.Options.Units.LinearUnitName);
      fulcrumLengthStatus.MessageType = CApCableStatusMessageType.Error;
    }
    return fulcrumLengthStatus;
  }

  private CApCableStatusMessage ComputeAttachmentAndPassNearStatus()
  {
    CApCableStatusMessage andPassNearStatus = new CApCableStatusMessage();
    if (this.IsParametersCreationMode() && this.m_cableStatusAnalysis.PassNearFrame != null && this.m_cableStatusAnalysis.AttachmentDataList.Any<CApFLEXAttachment>())
    {
      andPassNearStatus.MessageText = CApFLEXStringTable.PassNearIgnoredBecauseOfAttachmentsMessage;
      andPassNearStatus.MessageType = CApCableStatusMessageType.Warning;
    }
    return andPassNearStatus;
  }

  private CApCableStatusMessage ComputePassNearStatus()
  {
    CApCableStatusMessage passNearStatus = new CApCableStatusMessage();
    double validDistance;
    if (this.IsParametersCreationMode() && !this.m_cableStatusAnalysis.IsPassNearDistanceValid(out validDistance))
    {
      double currentLinearUnit = CApCableStatusAnalysis.ComputeValueWithCurrentLinearUnit(validDistance);
      passNearStatus.MessageText = string.Format(CApFLEXStringTable.PassNearInvalidMessage, (object) currentLinearUnit.ToString(CApCableUtility.NumericLinearFormat), (object) TxApplication.Options.Units.LinearUnitName);
      passNearStatus.MessageType = CApCableStatusMessageType.Error;
    }
    return passNearStatus;
  }

  private CApCableStatusMessage ComputeRobotAttachmentFrameStatus()
  {
    CApCableStatusMessage attachmentFrameStatus = new CApCableStatusMessage();
    TxRobot robot1;
    this.m_cableStatusAnalysis.CableFrameAttachmentRetriever.RetrieveAttachingRobot(this.m_cableStatusAnalysis.StartFrame, this.m_cableStatusAnalysis.AttributeModel.StartAttachPartTo, out robot1);
    TxRobot robot2;
    this.m_cableStatusAnalysis.CableFrameAttachmentRetriever.RetrieveAttachingRobot(this.m_cableStatusAnalysis.EndFrame, this.m_cableStatusAnalysis.AttributeModel.EndAttachPartTo, out robot2);
    if (TxRobot.op_Equality(robot1, (ITxObject) null) && TxRobot.op_Equality(robot2, (ITxObject) null))
    {
      attachmentFrameStatus.MessageText = CApFLEXStringTable.StartAndEndFrameAreNotAttachedMessage;
      attachmentFrameStatus.MessageType = CApCableStatusMessageType.Warning;
    }
    else if (TxRobot.op_Equality(robot1, (ITxObject) null))
    {
      attachmentFrameStatus.MessageText = CApFLEXStringTable.StartFrameIsNotAttachedMessage;
      attachmentFrameStatus.MessageType = CApCableStatusMessageType.Warning;
    }
    else if (TxRobot.op_Equality(robot2, (ITxObject) null))
    {
      attachmentFrameStatus.MessageText = CApFLEXStringTable.EndFrameIsNotAttachedMessage;
      attachmentFrameStatus.MessageType = CApCableStatusMessageType.Warning;
    }
    else if (this.IsParametersCreationMode() && !this.m_cableStatusAnalysis.AreAttachementAttachmentsFrameValid())
    {
      attachmentFrameStatus.MessageText = CApFLEXStringTable.AttachmentFrameIsNotAttachedMessage;
      attachmentFrameStatus.MessageType = CApCableStatusMessageType.Warning;
    }
    return attachmentFrameStatus;
  }

  private CApCableStatusMessage ComputeAttachmentsFrameAttachementStatus()
  {
    CApCableStatusMessage attachementStatus = new CApCableStatusMessage();
    TxRobot robot1;
    this.m_cableStatusAnalysis.CableFrameAttachmentRetriever.RetrieveAttachingRobot(this.m_cableStatusAnalysis.StartFrame, out robot1);
    TxRobot robot2;
    this.m_cableStatusAnalysis.CableFrameAttachmentRetriever.RetrieveAttachingRobot(this.m_cableStatusAnalysis.EndFrame, out robot2);
    ITxObject robot3 = !TxRobot.op_Inequality(robot1, (ITxObject) null) ? (ITxObject) robot2 : (ITxObject) robot1;
    if (this.IsParametersCreationMode() && !this.m_cableStatusAnalysis.AreAttachmentsAttachedToRobot(robot3))
    {
      attachementStatus.MessageText = CApFLEXStringTable.AttachmentsFrameAreNotAttachedInSameRobotMsg;
      attachementStatus.MessageType = CApCableStatusMessageType.Warning;
    }
    return attachementStatus;
  }

  private CApCableStatusMessage AreStartAndEndFramesEmpty()
  {
    CApCableStatusMessage cableStatusMessage = new CApCableStatusMessage();
    if (this.m_cableStatusAnalysis.StartFrame == null && this.m_cableStatusAnalysis.EndFrame == null)
    {
      cableStatusMessage.MessageText = CApFLEXStringTable.StartAndEndFrameMissingMessage;
      cableStatusMessage.MessageType = CApCableStatusMessageType.Incomplet;
    }
    return cableStatusMessage;
  }

  private CApCableStatusMessage IsStartFrameEmpty()
  {
    CApCableStatusMessage cableStatusMessage = new CApCableStatusMessage();
    if (this.m_cableStatusAnalysis.StartFrame == null)
    {
      cableStatusMessage.MessageText = CApFLEXStringTable.StartFrameMissingMessage;
      cableStatusMessage.MessageType = CApCableStatusMessageType.Incomplet;
    }
    return cableStatusMessage;
  }

  private CApCableStatusMessage IsEndFrameEmpty()
  {
    CApCableStatusMessage cableStatusMessage = new CApCableStatusMessage();
    if (this.m_cableStatusAnalysis.EndFrame == null)
    {
      cableStatusMessage.MessageText = CApFLEXStringTable.EndFrameMissingMessage;
      cableStatusMessage.MessageType = CApCableStatusMessageType.Incomplet;
    }
    return cableStatusMessage;
  }

  private CApCableStatusMessage IsOptimizationPointCloudLayerEmpty()
  {
    CApCableStatusMessage cableStatusMessage = new CApCableStatusMessage();
    if (this.IsPointCloudCreationMode() && this.m_cableStatusAnalysis.OptimizationPointCloudLayer == null)
    {
      cableStatusMessage.MessageText = CApFLEXStringTable.OptimizationPointCloudLayerMissingMessage;
      cableStatusMessage.MessageType = CApCableStatusMessageType.Incomplet;
    }
    return cableStatusMessage;
  }

  private CApFLEXAttachmentErrorMessage ComputeDistanceBetweenAttachmentsFrameAttachmentStatus()
  {
    bool flag = true;
    CApFLEXAttachmentErrorMessage errorMessage = new CApFLEXAttachmentErrorMessage()
    {
      Scope = CApFLEXAttachmentErrorMessage.EAttachmentMessageScope.Global
    };
    if (this.IsParametersCreationMode())
    {
      List<CApFLEXAttachment> cableOrderedList = this.m_cableStatusAnalysis.ComputeAttachmentsAlongCableOrderedList();
      List<CApFLEXAttachment>.Enumerator enumerator = cableOrderedList.GetEnumerator();
      if (enumerator.MoveNext())
      {
        CApFLEXAttachment current1 = enumerator.Current;
        double distance;
        CApCableUtility.ComputeDistanceBetweenFrames(this.m_cableStatusAnalysis.StartFrame, current1.ClosestFrameToStart, out distance);
        if (distance > current1.LowerLengthFromStart)
        {
          errorMessage.AttachmentType = current1.AttachmentType;
          errorMessage.DistanceFromAttachment1 = distance;
          errorMessage.AttachmentErrorType = this.GetAttachmentDistanceErrorType(current1);
          errorMessage.BoundType = CApFLEXAttachmentErrorMessage.EAttachmentBoundType.Minimum;
          errorMessage.AttachFrame1 = ((ITxObject) this.m_cableStatusAnalysis.StartFrame).Name;
          errorMessage.AttachFrame2 = ((ITxObject) current1.ClosestFrameToStart).Name;
          errorMessage.AttachmentRank = 0;
          flag = false;
        }
        if (flag)
          flag = this.ComputeRetractSystemSelfConsistencyStatus(current1, 0, ref errorMessage);
        if (flag)
        {
          CApFLEXAttachment capFlexAttachment1 = current1;
          int attachmentRank = 1;
          while (flag && enumerator.MoveNext())
          {
            CApFLEXAttachment current2 = enumerator.Current;
            CApCableUtility.ComputeDistanceBetweenFrames(capFlexAttachment1.FixedFrame, current2.ClosestFrameToStart, out distance);
            distance -= capFlexAttachment1.RetractionCapability;
            double num = capFlexAttachment1.LengthFromStart + distance;
            if (current2.LowerLengthFromStart < num)
            {
              errorMessage.AttachmentType = current2.AttachmentType;
              errorMessage.AttachmentErrorType = this.GetAttachmentDistanceErrorType(current2);
              errorMessage.DistanceFromAttachment1 = num;
              errorMessage.BoundType = CApFLEXAttachmentErrorMessage.EAttachmentBoundType.Minimum;
              errorMessage.AttachFrame1 = capFlexAttachment1.FixedFrameName;
              errorMessage.AttachFrame2 = ((ITxObject) current2.ClosestFrameToStart).Name;
              errorMessage.AttachmentRank = attachmentRank;
              flag = false;
            }
            if (flag)
              flag = this.ComputeRetractSystemSelfConsistencyStatus(current2, attachmentRank, ref errorMessage);
            capFlexAttachment1 = current2;
            ++attachmentRank;
          }
          if (flag)
          {
            CApFLEXAttachment capFlexAttachment2 = cableOrderedList.Last<CApFLEXAttachment>();
            CApCableUtility.ComputeDistanceBetweenFrames(this.m_cableStatusAnalysis.EndFrame, capFlexAttachment2.FixedFrame, out distance);
            double num = distance - capFlexAttachment2.RetractionCapability;
            if (this.m_cableStatusAnalysis.Length - capFlexAttachment2.LengthFromStart < num)
            {
              errorMessage.AttachmentType = capFlexAttachment2.AttachmentType;
              errorMessage.DistanceFromAttachment1 = this.m_cableStatusAnalysis.Length - num;
              errorMessage.BoundType = CApFLEXAttachmentErrorMessage.EAttachmentBoundType.Maximum;
              errorMessage.AttachFrame1 = capFlexAttachment2.FixedFrameName;
              errorMessage.AttachFrame2 = ((ITxObject) this.m_cableStatusAnalysis.EndFrame).Name;
              errorMessage.AttachmentErrorType = CApFLEXAttachmentErrorMessage.EAttachmentErrorType.AttachmentDistanceError;
              errorMessage.AttachmentRank = cableOrderedList.Count - 1;
            }
          }
        }
      }
    }
    return errorMessage;
  }

  private CApFLEXAttachmentErrorMessage.EAttachmentErrorType GetAttachmentDistanceErrorType(
    CApFLEXAttachment attachment)
  {
    return !(attachment is CApFLEXRetractSystemAttachmentType3) ? CApFLEXAttachmentErrorMessage.EAttachmentErrorType.AttachmentDistanceError : CApFLEXAttachmentErrorMessage.EAttachmentErrorType.AttachmentSecondaryDistanceError;
  }

  private bool ComputeRetractSystemSelfConsistencyStatus(
    CApFLEXAttachment attachment,
    int attachmentRank,
    ref CApFLEXAttachmentErrorMessage errorMessage)
  {
    bool consistencyStatus = true;
    if (attachment is CApFLEXRetractSystemAttachmentType3 systemAttachmentType3)
    {
      double distance;
      CApCableUtility.ComputeDistanceBetweenFrames(systemAttachmentType3.FixedFrame, systemAttachmentType3.SecondaryFixedFrame, out distance);
      if (systemAttachmentType3.LengthFromStart - systemAttachmentType3.SecondaryLengthFromStart < distance)
      {
        errorMessage.AttachmentType = systemAttachmentType3.AttachmentType;
        errorMessage.AttachmentErrorType = CApFLEXAttachmentErrorMessage.EAttachmentErrorType.AttachmentDistanceError;
        errorMessage.DistanceFromAttachment1 = systemAttachmentType3.SecondaryLengthFromStart + distance;
        errorMessage.BoundType = CApFLEXAttachmentErrorMessage.EAttachmentBoundType.Minimum;
        errorMessage.AttachFrame1 = systemAttachmentType3.FixedFrameName;
        errorMessage.AttachFrame2 = ((ITxObject) systemAttachmentType3.SecondaryFixedFrame).Name;
        errorMessage.AttachmentRank = attachmentRank;
        consistencyStatus = false;
      }
    }
    return consistencyStatus;
  }

  private bool IsParametersCreationMode()
  {
    return this.m_cableStatusAnalysis.CreationMode == CUiFLEXCreationMode.MANUAL;
  }

  private bool IsPointCloudCreationMode()
  {
    return this.m_cableStatusAnalysis.CreationMode == CUiFLEXCreationMode.FROM_POINT_CLOUD;
  }

  private delegate CApCableStatusMessage ErrorMessageDelegate();
}
